<?php
include 'include/functions.php';
include 'include/QuickPicks.php';
//set session save path
session_save_path($session_path);
// Initialize a session. 
session_start();
$count++;
$sessionId = session_id();
include 'include/processQuickPick.php';
require_once('include/Team.php');
dbConnect();
//check to see if a Weeknum value was passed, if not, set WeekNum to Weeknum.
if (($Weeknum == NULL) || ($Weeknum == "")) {
	$Weeknum = getWeek();
}

//check to make sure $Weeknum > 1 AND $Weeknum < 21
$Weeknum = checkWeekBounds($Weeknum);
if ($EnablePicks)
{
	if ($userID)
		enableQuickPicks($userID);
	else
		$needToLogin = true;
}
if($ReOrder)
	ReOrderByRecord($userID);
if ($userID)
	$ListTeams = getTeams($userID);
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="css/football.css" type="text/css">
	<script src="http://jquery.com/src/latest/"></script>
	<script type="text/javascript" src="scriptaculous-js-1.7.0/lib/prototype.js"></script>
    <script type="text/javascript" src="scriptaculous-js-1.7.0/src/scriptaculous.js"></script>
    <script type="text/javascript" src="scriptaculous-js-1.7.0/src/effects.js"></script>
    <script type="text/javascript" src="scriptaculous-js-1.7.0/src/dragdrop.js"></script>
    <script type="text/javascript" src="scriptaculous-js-1.7.0/src/controls.js"></script>
	<!-- <script src="scripts/ajax.js" type="text/javascript"></script> -->
	<script type="text/javascript" language="javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	 
   var http_request = false;
   function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      makeRequest('submitpicks2.php', getstr);
   }
	</script>
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->
			
			<table width="550" cellpadding="5" cellspacing="0">
				<tr>
					<td align="center" height="1"><h3>Quick Picks</h3></td>
				</tr>
				<tr>
					<td height="1">
					Quick picks are two fold:
					<ol>
						<li>They provide a way to make all your picks each week with one click.</li>
						<li>They are kind of like an insurance policy on your picks if you forget to make them.</li>
					</ol>
					You rank each team 1-32 (Simply drag &amp; drop the teams to order them from highest to lowest).
					In the event that you forget to make your picks before games are locked out, the system can automatically make your picks for each game based on which team you have ranked higher.  
					<p><b>NOTE:</b> The quick picks will not weigh your picks if you are in the weighted pool, and quick picks will not make a survivor pick if you are in the survival pool.</p>
					</td>
				</tr>
			</table>
				<table width="550" cellpadding="5" cellspacing="0">
					<tr>
					<td class="redbg">
						<table bgcolor="#FFFFFF" width="550" align="center">
						<tr>
						<td>
						<?
							if ($ListTeams)
							{
								echo "
								<ul class=\"qpsortablelist\" id=\"team_list\">";
								foreach ($ListTeams as $Team)
								{
									echo "<li id=\"team_".$Team->TeamName."\">"; 
									$Team->Display();
									echo "</li>\n";
								}
								echo "</ul>
								<hr color=\"#cb0000\" size=\"1\"/>
								<form name=\"QPForm\" action=\"$PHP_SELF\">
									<p align=\"center\">Reorder By Record Will adjust your Quick Pick list by sorting all 32 teams by record (ties broken by PointsFor & PointsAgainst).<br/>
									<input type=\"Submit\" name=\"ReOrder\" value=\"Reorder By Record\" /></p>
								</form>
								";
								?>						
									<script type="text/javascript">
									
										function updateOrder()
										{
											// turn on update message here
											//new Effect.Highlight('text',{startcolor:'#cccccc', endcolor:'#0066cc', restorecolor:'#0066cc', duration: 1.5});
											var options = {
															method : 'post',
															parameters : Sortable.serialize('team_list'),
															asynchronous: true,
															onComplete : function(request){
																// turn off update message here
																//new Effect.Highlight('text',{startcolor:'#0066cc', endcolor:'#cccccc', restorecolor:'#cccccc', duration: 2.0});
															}
														  };
										 
											new Ajax.Request('include/QPprocessor.php?func=<?=$userID?>', options);
										}
										Sortable.create('team_list', { onUpdate : updateOrder });
									</script>
								<?
							}
							else
							{
								if ($needToLogin == true)
									echo "You have to be a registed member and logged in to enable quick picks.<br/>";
								else
									echo "You first have to enable quick picks before you can rank teams.<br/>";
								echo "<form action=\"$PHP_SELF\"><input type=\"Submit\" name=\"EnablePicks\" value=\"Enable Quick Picks\" /></form>";
							}
						?></td>
						</tr>
						</table>
					</td>
					</tr>
				</table>
			<!-- InstanceEndEditable -->
			
			</div>

			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>